var api = require('../../utils/api');
var utils = require('../../utils/utils');

Page({
  data: {
    total: 0
  },
  onLoad: function (options) {
    var symbol = options.symbol;
    // this.setData({
    //   symbol: symbol
    // });
    var level = 'full';
    this.loadDepth(symbol, level);

  },
  loadDepth: function (symbol, level) {
    api.depth(symbol, level).then(res => {
      // console.log(res)
      var depthData = utils.formatDepth(res, 100);
      // 汇总金额
      var result = {};
      for (const side in depthData) {
        if (side == 'asks' || side == 'bids') {
          var someSideArray = depthData[side];
          result[side] = someSideArray.map((item, index) => {
            return item[0] * item[1];
          }).reduce((pre, cur, index, array) => {
            return pre + cur;
          });
        }
      }
      this.setData({
        depthData: depthData,
        total: result,
      });
    });
  },
})